import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path:"/",
    redirect:"/login"
  },
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  // 首页
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    redirect:"/home/home",
    children:[
      {
        path: 'home',
        name: 'home',
        component: () => import('../views/home/home.vue'),
      },   {
        path: 'xiang',
        name: 'xiang',
        component: () => import('../views/home/xaing.vue'),
      },   {
        path: 'shang',
        name: 'shang',
        component: () => import('../views/home/shang.vue'),
      }
    ]
  },
  // 商品
  {
    path: '/shang',
    name: 'shang',
    component: () => import('../views/shang/index.vue'),
    redirect:"/shang/fen",
    children:[
      {
        path: 'fen',
        name: 'fen',
        component: () => import('../views/shang/fen.vue'),
      },    {
        path: 'gui',
        name: 'gui',
        component: () => import('../views/shang/gui.vue'),
      }, {
        path: 'ping',
        name: 'ping',
        component: () => import('../views/shang/ping.vue'),
      }
    ]
  },
  // 订单
  {
    path:"/ding",
    name:"/ding",
    component: () => import('../views/ding/index.vue'),
    redirect:"/ding/ding",
    children:[
        {
          path: 'ding',
          name: 'ding',
          component: () => import('../views/ding/ding.vue'),
        }, {
          path: 'fa',
          name: 'fa',
          component: () => import('../views/ding/fa.vue'),
        }, {
          path: 'shou',
          name: 'shou',
          component: () => import('../views/ding/shou.vue'),
        }
    ]
  },
  // 会员
  {
    path:"/hui",
    name:"/hui",
    component: () => import('../views/hui/index.vue'),
    redirect:"/hui/hui",
    children:[
        {
          path: 'hui',
          name: 'hui',
          component: () => import('../views/hui/hui.vue'),
        },   {
          path: 'ji',
          name: 'ji',
          component: () => import('../views/hui/ji.vue'),
        },  {
          path: 'gao',
          name: 'gao',
          component: () => import('../views/hui/gao.vue'),
        }
    ]
  },
  // 设置
  {
    path:"/she",
    name:"/she",
    component: () => import('../views/she/index.vue'),
    redirect:"/she/ji",
    children:[
      {
        path: 'ji',
        name: 'ji',
        component: () => import('../views/she/ji.vue'),
      }, {
        path: 'wu',
        name: 'wu',
        component: () => import('../views/she/wu.vue'),
      }, {
        path: 'jiao',
        name: 'jiao',
        component: () => import('../views/she/jiao.vue'),
      },
    ]
  }
]
const router = new VueRouter({
    routes,
});

router.beforeEach((to, from, next) => {
    if (localStorage.getItem("token")) {
        next();
    } else {
        if (to.path == "/login") {
            next();
        } else {
            next("/login");
        }
    }
});

export default router;